package com.irdstudio.efp.esb.api.common;

import com.alibaba.fastjson.JSON;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.common.constant.EsbSysHeadEnums;
import com.irdstudio.efp.esb.common.server.req.EsbReqServiceBean;
import com.irdstudio.efp.esb.common.server.resp.EsbRespServiceBean;

/**
 * 处理只有 交易信息和交易的的响应: <br>
 * <p>
 * 0.1:caoxin:2019/4/18 12:50: TODO: <br>
 *
 * @author caoxin
 * @version 0.1
 * @date 2019/4/18 12:50
 * @since 2019/4/18 12:50
 */
public class EsbRespServiceHandler {
    /**
     * （响应码+响应信息）成功通用返回: <br>
     *
     * 0.1:caoxin:2019/4/18 13:33: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/18 13:33
     * @date 2019/4/18 13:33
     * @version 0.1
     */

    public static EsbRespServiceBean esbSuccessHandler(EsbReqServiceBean esbReqServiceBean){
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSON.toJSONString(new EsbRespHandlerBean(EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(), "交易成功")),
                EsbSysHeadEnums.RetStEnum.SUCCESS.getCode(),
                EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(),
                "交易成功");
    }


    /**
     * 自定义成功返回 Object为响应对象: <br>
     *
     * 0.1:caoxin:2019/4/18 13:34: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/18 13:34
     * @date 2019/4/18 13:34
     * @version 0.1
     */

    public static EsbRespServiceBean esbSuccessHandler(EsbReqServiceBean esbReqServiceBean, Object object){
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSON.toJSONString(object),
                EsbSysHeadEnums.RetStEnum.SUCCESS.getCode(),
                EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(),
                "交易成功");
    }


    /**
     * （响应码+响应信息）失败通用返回: <br>
     *
     * 0.1:caoxin:2019/4/18 13:33: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/18 13:33
     * @date 2019/4/18 13:33
     * @version 0.1
     */
    public static EsbRespServiceBean esbFailureHandler(EsbReqServiceBean esbReqServiceBean, Exception e){
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSON.toJSONString(new EsbRespHandlerBean(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(), e.getMessage())),
                EsbSysHeadEnums.RetStEnum.FAILURE.getCode(),
                EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(),
                e.getMessage());
    }

    /**
     * 自定义失败返回 Object为响应对象: <br>
     *
     * 0.1:caoxin:2019/4/18 13:34: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/18 13:34
     * @date 2019/4/18 13:34
     * @version 0.1
     */
    public static EsbRespServiceBean esbFailureHandler(EsbReqServiceBean esbReqServiceBean, String code, String msg){
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSON.toJSONString(new EsbRespHandlerBean(code, msg)),
                EsbSysHeadEnums.RetStEnum.FAILURE.getCode(),
                code,
                msg);
    }
    /**
     * 自定义失败返回 Object为响应对象: <br>
     *
     * 0.1:caoxin:2019/4/18 13:34: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/18 13:34
     * @date 2019/4/18 13:34
     * @version 0.1
     */
    public static EsbRespServiceBean esbFailureHandler(EsbReqServiceBean esbReqServiceBean, Object object, String code, String msg){
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSON.toJSONString(object),
                EsbSysHeadEnums.RetStEnum.FAILURE.getCode(),
                code,
                msg);
    }
}
